<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="../../../js/vue.js"></script>
    <title>sessionStorage</title>
</head>
<body>
    <button onclick="saveData()">点我保存一个数据</button>
    <button onclick="readData()">点我读取一个数据</button>
    <button onclick="deleteData()">点我删除一个数据</button>
    <button onclick="clearData()">点我清空所有数据</button>
    <script type="text/javascript">
        function saveData(){
            let p = {name:'张三',age:'12'}
            sessionStorage.setItem('msg','hello')
            sessionStorage.setItem('person', JSON.stringify(p))
        }
        function readData(){
            //如果读取的参数或对象不存在，则为null
            console.log(sessionStorage.getItem('msg'))
            const person = sessionStorage.getItem('person')
            console.log(JSON.parse(person))
        }
        function deleteData(){
            sessionStorage.removeItem('msg')
        }
        function clearData(){
            sessionStorage.clear()
        }
    </script>
</body>
</html>